//
//  HPCustomButton.m
//  HPZZTong
//
//  Created by handpay on 14-3-25.
//  Copyright (c) 2014年 Handpay. All rights reserved.
//

#import "HPCustomButton.h"

@implementation HPCustomButton

@synthesize textStr;

- (id) initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self initialize];
    }
    return self;
}
- (void) initialize{
    
    [self changeBackground:@"numberbuttonbg.png" highlight:@"numberbuttonbghover.png"];
}
- (void) awakeFromNib
{
    [self initialize];
}

- (void)setCustomImage:(NSString*)imageName{
    if ([NSString isNilOrEmpty:imageName]) {
        return;
    }
    UIImage* image = [UIImage imageNamed:imageName];
    [self setImage:image forState:UIControlStateNormal];
    [self setImage:image forState:UIControlStateHighlighted];
}

- (void)changeBackground:(NSString*)normal highlight:(NSString*)highlight{
    BOOL isNormal = [NSString isNilOrEmpty:normal];
    BOOL isHighl = [NSString isNilOrEmpty:highlight];
    if (isNormal && isHighl) {
        return;
    }
    
    if (!isNormal) {
        UIImage* bgImage = [UIImage imageNamed:normal];
        bgImage = [bgImage stretchableImageWithLeftCapWidth:6.0 topCapHeight:.0];
        [self setBackgroundImage:bgImage forState:UIControlStateNormal];
    }
    if (!isHighl) {
     
        UIImage* hoverImage = [UIImage imageNamed:highlight];
        hoverImage = [hoverImage stretchableImageWithLeftCapWidth:6.0 topCapHeight:.0];
        
        [self setBackgroundImage:hoverImage forState:UIControlStateHighlighted];
    }
    
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
